package com.itheima.service;

import com.itheima.dao.StudentDao;
import com.itheima.domain.Student;

import java.sql.Statement;
import java.util.ArrayList;

public class StudentService {

    private StudentDao studentDao = new StudentDao();

    //新增
    public void addStudent(Student student) {
        studentDao.addStudent(student);
    }

    public ArrayList<Student> findAllStudents() {
        return studentDao.findAllStudents();
    }

    //定义方法  判断学号是否存在
    public boolean isExists(String sid) {
//查所有
        ArrayList<Student> list = studentDao.findAllStudents();
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            //判断是否存在 相同 存在
            if (student.getSid().equals(sid)) {
                return true;
            }
        }
        //所有不同蔡不存在
        return false;
    }

    public void deleteStudent(String sid){
        studentDao.deleteStudent(sid);
    }

    public void updateStudent(String sid,Student student){
        studentDao.updateStudent(sid, student);
    }

}
